package ma.jeetconsulting.pocs.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class ModuleReport {

	private String moduleName;
	private final List<JavaFile> javaFiles;
	private Set<String> packages = new HashSet<>();
	
	public ModuleReport(List<JavaFile> javaFiles) {
		this.javaFiles = javaFiles;
	}
	
	public String getModuleName() {
		return moduleName;
	}
	
	public Map<String, List<String>> getClassesSortedByPackages() {
		Map<String, List<String>> result = new HashMap<>();
		for(String pacKage : getPackages())
			result.put(pacKage, getClassesInPackage(pacKage));
		return result;
	}
	
	private List<String> getClassesInPackage(String pacKage) {
		List<String> result = new ArrayList<>();
		for(JavaFile javaFile : javaFiles)
			if(javaFile.getPackageName().equals(pacKage))
				result.add(javaFile.getClassName());
		return result;
	}

	public int getNumberOfPackages() {
		return getPackages().size();
	}
	
	private Set<String> getPackages() {
		if(packages.size() == 0)
			for(JavaFile file : javaFiles)
				packages.add(file.getPackageName());
		return packages;
	}

	public int getNumberOfClasses() {
		return javaFiles.size();
	}
	
	public List<String> getAllClasses(){
		return null;
	}

	public void setModuleName(String moduleName) {
		this.moduleName = moduleName;
	}
}
